﻿using Newtonsoft.Json.Linq;
using System;
using System.Web;
using System.Web.Http;
using WebApi.Services;

namespace WebApi.Controllers
{
    [RoutePrefix("api/Admin/Inventory")]
    public class InventoryController : ApiController
    {
        [Route("AddSKU"), HttpPost]
        public string AddSKU()
        {
            var req = HttpContext.Current.Request;
            MyInventory.CreateSKU(int.Parse(req["pro_id"]), req["sku_label1"], req["sku_label2"], req["sku_pic"], req["sku_code"], int.Parse(req["sku_stock"]), decimal.Parse(req["sku_cost"]), decimal.Parse(req["sku_refprice"]), decimal.Parse(req["sku_crtprice"]), int.Parse(req["sku_wrnstock"]));
            return "";
        }


        [Route("SKUInfo"), HttpGet]
        public JObject SKUInfo()
        {
            var req = HttpContext.Current.Request;
            return MyInventory.GetSKU(long.Parse(req["sku_id"]));

        }


        [Route("SKUlist"), HttpGet]
        public JArray SKUList()
        {
            var req = HttpContext.Current.Request;
            return MyInventory.SKUList(int.Parse(req["pro_id"]));
                
        }

        [Route("ChangeSKU"), HttpGet]
        public Boolean ChangeSKU()
        {
            var req = HttpContext.Current.Request;
            MyInventory.ChangeSKU(int.Parse(req["sku_id"]), req["sku_label1"], req["sku_label2"], req["sku_pic"], req["sku_code"], int.Parse(req["sku_stock"]), decimal.Parse(req["sku_cost"]), decimal.Parse(req["sku_refprice"]), decimal.Parse(req["sku_crtprice"]), int.Parse(req["sku_wrnstock"]));
            return true;
        }

        [Route("DeleteSKU"), HttpGet]
        public Boolean DeleteSKU()
        {
            var req = HttpContext.Current.Request;
            return MyInventory.DeleteSKU(int.Parse(req["sku_id"]), int.Parse(req["pro_id"]));
        }



        //[Route("GetSKU_Id"), HttpGet]
        //public JObject GetSKU_Id()
        //{
        //    var req = HttpContext.Current.Request;
        //    return MyInventory.GetSKU_Id(long.Parse(req["pro_id"]));
        //}
    }
}
